﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.IO;
using System.Collections.Generic;
using Liquifier;

namespace LiquifierTest
{
    /// <summary>
    ///This is a test class for LiquiferTest and is intended
    ///to contain all LiquiferTest Unit Tests
    ///</summary>
    public partial class LiquiferAttributesTest
    {
        #region Interface and Interface use Tests

        [Liquifiable(Serialisation.Public,Serialisation.None)]
        public class LiquifyInterfacedClass : ILiquify, ISolidify
        {
            public string serialisedString;
            private string nonSerialisedStringOne;
            private string nonSerialisedStringTwo;
            private string nonSerialisedStringThree;
            private string nonSerialisedStringFour;

            public string serialisedProperty { get; set; }

            public void OnLiquify(Liquifer liquifier)
            {
                liquifier.AddEntryForSerialisation(nonSerialisedStringTwo, "nonSerialisedStringTwo", SerialisedMemberFlags.Default);
                liquifier.AddEntryForSerialisation(nonSerialisedStringThree, "nonSerialisedStringThree", SerialisedMemberFlags.DoNotProcessOnSolidify);
                liquifier.AddEntryForSerialisation(nonSerialisedStringFour, "nothing", SerialisedMemberFlags.DoNotProcessOnSolidify);

                liquifier.AddEntryForSerialisation(serialisedProperty, "serialisedProperty", SerialisedMemberFlags.Default);                
            }

            public void OnSolidified(Liquifer solidifier)
            {
                this.nonSerialisedStringFour = solidifier.GetDeserialisedEntry("nothing") as string;
            }

            public void Initialise()
            {
                 serialisedString = "yes";
                 nonSerialisedStringOne = "yes";
                 nonSerialisedStringTwo = "yes";
                 nonSerialisedStringThree = "yes";
                 nonSerialisedStringFour = "yes";

                 serialisedProperty = "yes";
            }

            public void Verify()
            {
                //seralised string is public and so should be serialised
                Assert.AreEqual("yes", serialisedString);

                //nonserialisedone is private and not used in any other way and so should not be
                Assert.AreEqual(null, nonSerialisedStringOne);

                //nonserialisedtwo is added explicitly, with an id equivalent to its member name, and so will be processed
                Assert.AreEqual("yes", nonSerialisedStringTwo);

                //nonserialisedthree is added, with the correct name, but is flagged to ignore on deserialisation so will not be processed
                Assert.AreEqual(null, nonSerialisedStringThree);

                //nonserialisedfour is added, with an incorrect name, but is retrieved in solidify and so is restored
                Assert.AreEqual("yes", nonSerialisedStringFour);

                //properties should work in exactly the same way as fields when it comes to matching names for repatriation
                Assert.AreEqual("yes", serialisedProperty);
            }

        }


        [TestMethod()]
        public void DoInterfacesAndPublicLiquifierMethodsWork()
        {
            LiquifyInterfacedClass before = new LiquifyInterfacedClass();

            before.Initialise();

            LiquifyInterfacedClass after = DoLiquifify(before);

            after.Verify();

        }

        #endregion     

    }
}
